<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
<%@ include file="/WEB-INF/views/include/easyui.jsp"%>
</head>
<body>
	<script src="<%=path%>/static/plugins/My97DatePicker/WdatePicker.js"
				type="text/javascript"></script>
		<div id="tr" style="padding: 5px; height: auto">
		<form id="grantPermiss" action="<%=path %>/system/permission/grantPermiss"
			method="post">
			<table>
				<tr>
				<td>有效期起：</td><td><input type="text" name="expireBeg" value="${result.expireBeg}"
						class="easyui-my97" datefmt="yyyy-MM-dd" data-options="required:true"/></td>
					<td>有效期止：</td><td><input type="text" name="expireEnd" value="${result.expireEnd}"
						class="easyui-my97" datefmt="yyyy-MM-dd" data-options="required:true" /></td></tr>
						<input type="hidden" name="roleId" value="${result.roleId}" />
						<input type="hidden" name="orgId" value="${result.orgId}" />
						<input type="hidden" name="orgType" value="${result.orgType}" />
						<input type="hidden" name="permissions" id="permissions" value="" data-options="required:true"/>
			</table>
		</form>
		</div>
		<table id="teamRole"></table>
	
<script>
var have_permissions="${havePermissions}";

var permissionDg;	//权限datagrid
$('#grantPermiss').form({
	onSubmit : function(param) {

		var isValid = $(this).form('validate');
		var checkPermissionList=[];
		var data=$('#teamRole').treegrid('getSelections');
		for(var i=0,j=data.length;i<j;i++){
			checkPermissionList.push(data[i].id);
		}
		$("#permissions").val(checkPermissionList.join(";"));
		return isValid; // 返回false终止表单提交
	},
	success : function(data) {
		if (successTip(data, dg, d))
			dg.treegrid('reload');
	}
});
$(function(){   
	permissionDg=$('#teamRole').treegrid({   
		method: "get",
	    url:'<%=path %>/system/permission/userPermissions', 
	    fit : true,
		fitColumns : true,
		border : false,
		idField : 'id',
		treeField:'name',
		parentField : 'pid',
		iconCls: 'icon',
		animate:true, 
		rownumbers:true,
		singleSelect:false,
		striped:true,
	    columns:[[    
			 
	        {field:'id',title:'id',hidden:true,width:100},    
	        {field:'name',title:'名称',width:100},
	        {field:'description',title:'描述',width:100,tooltip: true}
	    ]],
	    onLoadSuccess:function(row, data){
	    	
	    	if(typeof(have_permissions)!="undefined"){ 
	    		have_permissions=eval("("+have_permissions+")");
	    		if(typeof(have_permissions)=="object"){
	    			for(var i=0,j=have_permissions.length;i<j;i++){
		    			permissionDg.treegrid('select',have_permissions[i]);
		    		}
	    		}
	    		
	    	} 
	    },
        toolbar:'#tr',
        dataPlain: true
	});
	
	
});
</script>
</body>
</html>